package com.example.simin_manage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.simin_manage.dto.PerformanceLogVO;
import com.example.simin_manage.entity.PerformanceLog;
import com.example.simin_manage.mapper.PerformanceLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @description:
 * @author: panpan
 * @time: 2025/9/21
 */
@Service
public class PerformanceLogService {

    @Autowired
    private PerformanceLogMapper performanceLogMapper;

    public IPage<PerformanceLogVO> listLogs(Long leaderId, Long userId, String startDate, String endDate,
                                            int pageNum, int pageSize) {
        Page<PerformanceLogVO> page = new Page<>(pageNum, pageSize);
        List<PerformanceLogVO> list = performanceLogMapper.findByLeaderIdWithFilter(leaderId, userId, startDate, endDate);
        page.setRecords(list);
        page.setTotal(list.size());
        return page;
    }
    /**
     * 删除所有日志
     */
    public void deleteAll() {
        performanceLogMapper.delete(null); // MyBatis-Plus delete(null) => 清空表
    }
}
